**************************************************
**** Immigration and International Law
**** Descriptive Statistics
**** Replication .do file (1 of 3)
**** Margaret E. Peters 
**** July 2018


version 13.1
use "bilateral_treaties_final.dta", clear

**Figure 1
preserve
	collapse (sum) treaty1, by(year)
	gen cumtotal=sum(treaty1)
	twoway (bar treaty1 year, bcolor(gs13)) (line cumtotal year, lcolor(black) yaxis(2)) ////
	(pci 0 1973 30 1973  , lcolor(gs4) lpattern(dash)) (pci 0 1990 30 1990 , lcolor(gs4) lpattern(dash)), ////
	ytitle("") ytitle("", axis(2)) name(tottreaties, replace) xscale(range(1945 2015)) xlabel(1945(10)2015) ////
	graphregion(margin(small) fcolor(white) lcolor(white)) legend(off)   yscale(range(0 30))   ylabel(0(10)30) ylabel(0(100)800, axis(2)) ////
	 l1title("Treaties Per Year", size(small)) r1title("Cumulative Total", size(small)) xtitle("Year", size(small))  //// 
	 text(19 1950 "Treaties Per Year", size(vsmall)) ////
	 text(16 1982 "Cumulative Total", size(vsmall)) 
	 *graph export Graph_treaty_by_year_bw.pdf, replace
	 graph export Graph_treaty_by_year_bw.tif, width(7200) replace
restore

***Summary stats on treaties	
tab treaty2
tab treaty2 if ccode1==200
tab treaty2 if ccode1==220
tab treaty2 if ccode1==255 /*Germany*/	
tab treaty2 if ccode1==260 /*West Germany*/



**Receivers by year
preserve
	collapse (sum) treaty1, by(ccode1 year)
	sort year
	save "receivers_by_year.dta", replace
	gen period=1 if year>1945 & year<1974
	replace period=2 if year>=1974 & year<1990
	replace ccode1=260 if ccode1==255 | ccode1==265
	replace period=3 if year>=1990
	collapse (sum) treaty1, by(ccode1 period)
	merge m:m ccode1 using "COWccode1.dta"
	drop if _merge==2
	drop stateabb  styear stmonth stday endyear endmonth endday version _merge
	sort period
	export excel using "data for maps.xls", firstrow(variables) replace
	save "treaties_by_period_for_maps.dta", replace
restore


**Senders by year
preserve
	collapse (sum) treaty1, by(ccode2 year)
	sort year
	save "senders_by_year.dta", replace
	gen period=1 if year>1945 & year<1974
	replace period=2 if year>=1974 & year<1990
	replace ccode2=260 if ccode2==255 | ccode2==265
	replace period=3 if year>=1990
	collapse (sum) treaty1, by(ccode2 period)
	merge m:m ccode2 using "COWccode2.dta"
	drop if _merge==2
	drop stateabb  styear stmonth stday endyear endmonth endday version _merge
	sort period
	export excel using "data for maps_senders.xls", firstrow(variables) replace
	save "treaties_by_period_for_maps_senders.dta", replace
restore



***summary statistics on what is in the treaties
*Number of treaties coded
tab f_industry 


*Commission to help with adjudication/ implementation
tab f_disputestate

**Sending state has say in number sent
tab f_snumber

**Number listed
tab f_number2


*screening
 tab f_sscreens
  tab f_sscreenhealth
  tab f_sscreeneduc
 tab f_ssceenexper
  tab f_sscreentrain
*skills mentioned or screended for
tab f_skillmentioned




*****Effect of signing treaty today on signing a treaty in the future
***WILL NEED TO RUN "Regression_analysis_replication.do FIRST TO CREATE DATASET"
use  "treaty_dataset_replication.dta", clear

duplicates drop dyadid year, force

tsset dyadid year

sort dyadid year
***Do receiving states sign with the same sending state again?
by dyadid: gen origin_lead1=origin[_n+1]
by dyadid: gen origin_lead2=origin[_n+2]
by dyadid: gen origin_lead3=origin[_n+3]
by dyadid: gen origin_lead4=origin[_n+4]
by dyadid: gen origin_lead5=origin[_n+5]
by dyadid: gen origin_lead6=origin[_n+6]
by dyadid: gen origin_lead7=origin[_n+7]
by dyadid: gen origin_lead8=origin[_n+8]
by dyadid: gen origin_lead9=origin[_n+9]
by dyadid: gen origin_lead10=origin[_n+10]
by dyadid: gen origin_lead11=origin[_n+11]
by dyadid: gen origin_lead12=origin[_n+12]
by dyadid: gen origin_lead13=origin[_n+13]
by dyadid: gen origin_lead14=origin[_n+14]
by dyadid: gen origin_lead15=origin[_n+15]
by dyadid: gen origin_lead16=origin[_n+16]
by dyadid: gen origin_lead17=origin[_n+17]
by dyadid: gen origin_lead18=origin[_n+18]
by dyadid: gen origin_lead19=origin[_n+19]
by dyadid: gen origin_lead20=origin[_n+20]

tab origin_lead1 if origin==1
tab origin_lead2 if origin==1
tab origin_lead3 if origin==1
tab origin_lead4 if origin==1
tab origin_lead5 if origin==1

egen next5years=rowtotal(origin_lead1 origin_lead2 origin_lead3 origin_lead4 origin_lead5)
egen next6to10years=rowtotal(origin_lead6 origin_lead7 origin_lead8 origin_lead9 origin_lead10)
egen next11to20years=rowtotal(origin_lead11 origin_lead12 origin_lead13 origin_lead14 origin_lead15 ////
 origin_lead16 origin_lead17 origin_lead18 origin_lead19 origin_lead20)

tab next5year if origin==1
tab next6to10years if origin==1
tab next11to20years if origin==1

**Do receiving states sign with other similar sending states?
** Competition between regional receiving states
gen region2=0 if ccode1<100
replace region2=1 if ccode1>=100 & ccode1<200
replace region2=2 if ccode1>=200 & ccode1<400
replace region2=3 if ccode1>=400 & ccode1<600
replace region2=4 if ccode1>=600 & ccode1<700
replace region2=5 if ccode1>=700 & ccode1<900
replace region2=6 if ccode1>=900 

sort ccode1 year region2
by ccode1 year region2: egen simsending=total(origin)  
by ccode1 year region2: egen simsending_lead1=total(origin_lead1)  
by ccode1 year region2: egen simsending_lead2=total(origin_lead2)  
by ccode1 year region2: egen simsending_lead3=total(origin_lead3)  
by ccode1 year region2: egen simsending_lead4=total(origin_lead4)  
by ccode1 year region2: egen simsending_lead5=total(origin_lead5)  

gen simsending_wo=simsending-origin
gen simsending_wo_lead1=simsending_lead1-origin_lead1
gen simsending_wo_lead2=simsending_lead1-origin_lead2
gen simsending_wo_lead3=simsending_lead1-origin_lead3
gen simsending_wo_lead4=simsending_lead1-origin_lead4
gen simsending_wo_lead5=simsending_lead1-origin_lead5

egen simsending_sameplus5=rowtotal(simsending_wo simsending_wo_lead1 simsending_wo_lead2 simsending_wo_lead3 simsending_wo_lead4 simsending_wo_lead5)
tab simsending_sameplus5 if origin==1
egen simsending_plus5=rowtotal( simsending_wo_lead1 simsending_wo_lead2 simsending_wo_lead3 simsending_wo_lead4 simsending_wo_lead5)
tab simsending_plus5 if origin==1
